package com.newegg.research;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.regex.Pattern;

public class StringTokenizer
{
	public static final int OTHER_SYMBOLS = 4;
	public static final int CHINESE_CHAR = 3;
	public static final int UPPERCASE_LETTER = 2;
	public static final int LOWERCASE_LETTER = 1;
	public static final int DIGITAL = 0;
	private static Set<String> StopWords;

	public void setStopWords(String stopword)
	{
		for (int i = 0; i < stopword.length(); i++)
		{
			StopWords.add(stopword.charAt(i) + "");
		}
	}

	public static void main(String[] args)
	{
		StringTokenizer st = new StringTokenizer();
		Scanner scanner = new Scanner(System.in);
		String line = null;
		while ((line = scanner.nextLine()) != null)
		{
			List<String> c = st.participle(line);
			for (String s : c)
				System.out.println(s);
		}
	}

	public List<String> participle(String s)
	{
		final Pattern blank_space = Pattern.compile("\\s+");
		char[] input = s.toCharArray();
		List<String> result = new ArrayList<String>(s.length() >> 1);
		StringBuffer buffer = new StringBuffer();

		int prevType = OTHER_SYMBOLS;
		for (int i = 0; i < input.length; i++)
		{
			char c = input[i];
			if (StopWords != null && StopWords.contains(c + ""))
			{
				if (buffer.length() > 0)
				{
					result.add(buffer.toString());
					buffer = new StringBuffer();
				}
				prevType = OTHER_SYMBOLS;
			} else
			{
				int type = getType(c);

				if (prevType == CHINESE_CHAR && type == CHINESE_CHAR
						&& buffer.length() > 0)
				{
					buffer.append(c);
					result.add(buffer.toString());
					buffer = new StringBuffer(c+"");
				} else if (prevType == CHINESE_CHAR && type < CHINESE_CHAR)
				{
					if(buffer.length() > 1)
						result.add(buffer.toString());
					buffer = new StringBuffer(c + "");
				} else if (prevType < CHINESE_CHAR && type == CHINESE_CHAR)
				{
					result.add(buffer.toString());
					buffer = new StringBuffer(c+"");
				} else if (prevType < UPPERCASE_LETTER
						&& type == UPPERCASE_LETTER && buffer.length() > 1)
				{
					result.add(buffer.toString());
					buffer = new StringBuffer(c+"");
				} else if (type == OTHER_SYMBOLS)
				{
					if (buffer.length() > 0)
					{
						if(buffer.length() > 1)
							result.add(buffer.toString());
						buffer = new StringBuffer();
					}
					buffer.append(c);
					result.add(buffer.toString());
					buffer = new StringBuffer();
				} else
					buffer.append(c);

				prevType = type;
			}
		}
		if(buffer.length() > 0)
			result.add(buffer.toString());
		
		for(int i=result.size()-1;i>-1;i--)
		{
			String token = result.get(i);
			if(blank_space.matcher(token).matches())
//			if(token.matches("\\s+"))
				result.remove(i);
		}
		return result;
	}

	private int getType(char c)
	{
		switch (Character.getType(c))
		{
		case Character.LOWERCASE_LETTER:
			return LOWERCASE_LETTER;
		case Character.UPPERCASE_LETTER:
			return UPPERCASE_LETTER;
		case 5:
			return CHINESE_CHAR;
		case Character.DECIMAL_DIGIT_NUMBER:
			return DIGITAL;
		default:
			if (c == '.')
				return DIGITAL;
			else
				return OTHER_SYMBOLS;
		}
	}
}
